home *** CD-ROM | disk | FTP | other *** search
- #include <Types.h>
- #include <Memory.h>
- #include <Quickdraw.h>
- #include <Fonts.h>
- #include <ToolUtils.h>
- #include <Icons.h>
- #include <Controls.h>
- #include <Gestalt.h>
- #include <Resources.h>
-
- #include "GetDominantDevice.h"
-
- static Boolean IsActiveScreenDevice(GDHandle theDevice);
- static long GetRectArea(Rect r);
-
- // ---------------------------------------------------------------------------
-
- /*
- The following routines were written by Norman Basham.
- They were taken from "Monitors.cpp"
-
- Thanks a mil, Norman!
- */
- #pragma mark === Norman Basham ===
-
- // ------------------------------------------------------------------------
- // Given rect r, which device does it overlap most. An example of its use
- // would be passing in (**wp->visRgn).rgnBBox to find out which device a
- // window is overlapping the most, as in the case of zooming a window.
- // ------------------------------------------------------------------------
- GDHandle GetDominantDevice (Rect *r)
- {
- GDHandle aGDevice;
- GDHandle bigGDevice;
- Rect screenRect;
- Rect sectRect;
- long area;
- long biggestArea = 0L;
-
- aGDevice = GetDeviceList (); // start at begining of device list
- while (aGDevice != nil) // loop if device exists
- {
- if (IsActiveScreenDevice (aGDevice)) // if device is a monitor and active
- {
- screenRect = (**aGDevice).gdRect; // get the devices global rect
- SectRect (&screenRect, r, §Rect); // get overlapping rect of device and r
-
- area = GetRectArea (sectRect); // changed 3/21/94
- if (area > biggestArea) // if overlapping rect has the biggest area
- {
- bigGDevice = aGDevice; // set big device to current device
- biggestArea = area; // set big area to current area
- }
-
- aGDevice = GetNextDevice (aGDevice); // check next device in list
- }
- }
-
- return bigGDevice; // return device containing biggest portion of r
- }
-
- // ------------------------------------------------------------------------
- // Given a device, return wether it is a monitor and wether it's active
- // ------------------------------------------------------------------------
- Boolean IsActiveScreenDevice(GDHandle theDevice)
- {
- return (
- (TestDeviceAttribute (theDevice, screenDevice)) &&
- (TestDeviceAttribute (theDevice, screenActive))
- );
- }
-
- long GetRectArea(Rect r)
- {
- Rect temp = r;
-
- OffsetRect (&temp, -temp.left, -temp.top); // rids us of neg values
- return (long) temp.right * temp.bottom; // return width x heigth
- }